package top.milkbox.core;

import java.util.List;

public class PageBean<T> {

    private int totalCount; // 总记录数
    // 总页码数 = 总记录数 % 每页显示条数 == 0 ? 总记录数 / 每页显示条数 : 总记录数 / 每页显示条数 + 1
    private int totalPage;
    private List<T> list; // 每页的数据
    private int currentPage; // 当前页码
    private int rows; // 每页显示的条数

    /**
     * 使用此方法创建的对象中，会自动计算totalPage总页码数
     *
     * @param totalCount  总记录数
     * @param list        每页的数据
     * @param currentPage 当前页码
     * @param rows        每页显示的条数
     */
    public PageBean(int totalCount, List<T> list, int currentPage, int rows) {
        this.totalPage = totalCount % rows == 0 ? totalCount / rows : totalCount / rows + 1;
        this.totalCount = totalCount;
        this.list = list;
        this.currentPage = currentPage;
        this.rows = rows;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "totalCount=" + totalCount +
                ", totalPage=" + totalPage +
                ", list=" + list +
                ", currentPage=" + currentPage +
                ", rows=" + rows +
                '}';
    }

    public PageBean() {
    }
}
